package scms.job;

import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;

import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.JobHandler;
import com.xxl.job.core.log.XxlJobLogger;

import lac.model.core.persistent.Session;

@JobHandler(value="stockCheckNumJob")
@Service
public class StockCheckNumJob extends ModelIJobHandler{

	
	@Override
	public ReturnT<String> execute(String param) throws Exception {
		
		Session session = getSession();
		List<Map<String,Object>>stocks=  session.query("Stock");
		if(stocks != null){
			XxlJobLogger.log("stocks num is "+stocks.size());
			for(Map<String,Object> stock : stocks ){
				Integer checkNum = stock.get("checkNum")==null?0:(Integer)stock.get("checkNum");
				stock.put("checkNum", checkNum+1);
				stock.put("jobParam", param);
			}
			session.batchUpdate("Stock", stocks);
		}
		return SUCCESS;
	}

}
